package com.hhkj.study.api.user.enums;

import cn.hutool.core.util.ObjectUtil;
import com.hhkj.study.admin.course.enums.CourseAssocResourceTypeEnum;
import com.hhkj.study.api.user.model.res.ApiCustomerUserCourseStructureRes;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.function.Predicate;

/**
 * 课程表不同的来源有不同的判断
 * @Author luowu
 * @Date 2024/10/14 涵 13:35:43
 */
@Getter
@AllArgsConstructor
public enum CourseStructQuerySourceEnum {

    /**
     * 课程表结构查询来源
     */
    TIME_TABLE(1, "课程表", (item) -> true),

    QUESTION_BANK(2, "题集", (item) -> ObjectUtil.isNotNull(item.getQuestionId())),

    VIDEO_PLAY(3, "视频播放", (item) -> CourseAssocResourceTypeEnum.CAN_ASSOC_RESOUCE_TYPE_LIST.contains(item.getType())),
    ;

    /**
     * 来源类型
     */
    private Integer code;
    /**
     * 来源处
     */
    private String desc;

    /**
     * 类型针对的判断方法
     */
    private final Predicate<ApiCustomerUserCourseStructureRes> predicate;

    public static Predicate<ApiCustomerUserCourseStructureRes> getByCode(Integer code) {
        for (CourseStructQuerySourceEnum item : values()) {
            if (item.getCode().equals(code)) {
                return item.predicate;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return String.valueOf(code);
    }
}
